
//Simple Instantiation of a Prefab at Start

    var redPrefab : GameObject;
    var bluePrefab : GameObject;
    var yellowPrefab : GameObject;
    var greenPrefab : GameObject;
    var whitePrefab : GameObject;
    var blackPrefab : GameObject;
    var numTypes : int;
   	var typeToMake : int;
   	var startRows : int;
	var refillColumn : boolean;
   
   	var toRefill : GameObject[] = null;	
	var stillMoving : GameObject[] = null;
	
function Start() {
   		numTypes = 6; //start with 5 colors
   		
   		refillColumn = false;
   		FillBoard();
   		
   		Physics.gravity = Vector3(0.0, -1000.0, 0.0);
   		
   		
   		
   		
   	}
   	


function CreateBall() {
	typeToMake = Random.Range(0,numTypes);
    	
    	if (typeToMake == 0) {
    		Instantiate(redPrefab, transform.position, transform.rotation);
    	}
    	else if (typeToMake == 1) {
    		Instantiate(bluePrefab, transform.position, transform.rotation);
    	}
		else if (typeToMake == 2) {
    		Instantiate(yellowPrefab, transform.position, transform.rotation);
    	}
    	else if (typeToMake == 3) {
    		Instantiate(greenPrefab, transform.position, transform.rotation);
    	}
    	else if (typeToMake == 4) {
    		Instantiate(whitePrefab, transform.position, transform.rotation);
    	}
    	else if (typeToMake == 5) {
    		Instantiate(blackPrefab, transform.position, transform.rotation);
    	}
    	else {
    	//do nothing
    	}
}//end createball

function FillBoard() {
	CreateBall();
	yield WaitForSeconds(0.2);
	CreateBall();
	yield WaitForSeconds(0.2);
	CreateBall();
	yield WaitForSeconds(0.2);
	CreateBall();
	yield WaitForSeconds(0.2);
	CreateBall();
	yield WaitForSeconds(0.2);
	CreateBall();
	yield WaitForSeconds(0.2);
	CreateBall();
	yield WaitForSeconds(0.2);
	CreateBall();
}//end fillboard

function Refill() {
	yield WaitForSeconds(1.0);
	//Debug.Log("Here F");
	toRefill = GameObject.FindGameObjectsWithTag("F");
	stillMoving = GameObject.FindGameObjectsWithTag("Moving");
	
	if (stillMoving.Length == 0){
		if (toRefill != null){
			//Debug.Log(toRefill.Length);
			
			for (var i = 8-toRefill.Length; i > 0; i = i-1) {
				CreateBall();
				yield WaitForSeconds(0.2);
		
			}
					
		}
			 	
 	}
}//end refill